
package View;

import Control.ctrFornecedor;
import java.awt.GraphicsEnvironment;
import java.sql.SQLException;
import java.util.ArrayList;import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.text.MaskFormatter;
;
import javax.swing.JOptionPane;

public class limFornecedor extends javax.swing.JFrame {

    private final ctrFornecedor control;
    private MaskFormatter maskCNPJ, maskCEP, maskCOM, maskCEL;

    public limFornecedor(ctrFornecedor objPrincipal) {
        control = objPrincipal;
        initComponents();
        //Centraliza janela
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        int x = ge.getCenterPoint().x - (this.getWidth()/2);
        int y = ge.getCenterPoint().y - (this.getHeight()/2);
        setLocation(x, y);
        //Setar foco na interface superior
        JDialog dia = new JDialog();
        dia.setModal(true);
        dia.setContentPane(getContentPane());
        dia.setBounds(this.getBounds());
        dia.setVisible(true);
        dia.setResizable(false);
    }

    private void setAtributos(ArrayList <String> result) {
        field_codigo.setText("");
        field_codigo.setText(result.get(0));
        field_nomeFantasia.setText(result.get(1));
        field_marca.setText(result.get(2));
        field_cnpj.setText(result.get(3));
        field_contato.setText(result.get(4));
        field_email.setText(result.get(5));
        field_site.setText(result.get(6));
        field_tel_celular.setText(result.get(7));
        field_tel_comercial.setText(result.get(8));
        field_end_rua.setText(result.get(9));
        field_end_bairro.setText(result.get(10));
        field_end_cep.setText(result.get(11));
        field_end_cidade.setText(result.get(12));
    }

    private void limpaFields(){
        field_pesquisa.setText("");
        field_codigo.setText("");
        field_nomeFantasia.requestFocus();
        field_nomeFantasia.setText("");
        field_marca.setText("");
        field_cnpj.setText("");
        field_contato.setText("");
        field_email.setText("");
        field_site.setText("");
        field_tel_celular.setText("");
        field_tel_comercial.setText("");
        field_end_rua.setText("");
        field_end_bairro.setText("");
        field_end_cep.setText("");
        field_end_cidade.setText("");
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        label_titulo = new javax.swing.JLabel();
        panel_fornecedor = new javax.swing.JPanel();
        botao_primeiro = new javax.swing.JButton();
        botao_anterior = new javax.swing.JButton();
        field_codigo = new java.awt.TextField();
        botao_proximo = new javax.swing.JButton();
        botao_ultimo = new javax.swing.JButton();
        panel_pesquisar = new javax.swing.JPanel();
        field_pesquisa = new javax.swing.JTextField();
        label_pesquisar = new javax.swing.JLabel();
        botao_gravar = new javax.swing.JButton();
        botao_excluir = new javax.swing.JButton();
        botao_novo = new javax.swing.JButton();
        botao_alterar = new javax.swing.JButton();
        panel_dados_fornecedor = new javax.swing.JPanel();
        label_marca = new javax.swing.JLabel();
        field_marca = new javax.swing.JTextField();
        label_email = new javax.swing.JLabel();
        label_cnpj = new javax.swing.JLabel();
        field_email = new javax.swing.JTextField();
        field_site = new javax.swing.JTextField();
        label_nomeFantasia = new javax.swing.JLabel();
        field_nomeFantasia = new javax.swing.JTextField();
        label_site = new javax.swing.JLabel();
        field_contato = new javax.swing.JTextField();
        label_contato = new javax.swing.JLabel();
        try {
            maskCNPJ = new MaskFormatter("##.###.###/####-##");
        }
        catch (Exception ex){
            System.out.println("Erro ao setar máscara no field_cnpj do fornecedor.");
        }
        field_cnpj = new JFormattedTextField(maskCNPJ);
        panel_endereco = new javax.swing.JPanel();
        field_end_rua = new javax.swing.JTextField();
        field_end_bairro = new javax.swing.JTextField();
        label_end_cidade = new javax.swing.JLabel();
        label_end_rua = new javax.swing.JLabel();
        label_end_bairro = new javax.swing.JLabel();
        label_end_cep = new javax.swing.JLabel();
        try {     maskCEP = new MaskFormatter("##.###-###"); } catch (Exception ex){     System.out.println("Erro ao setar máscara no field_end_cep do fornecedor."); }
        field_end_cep = new JFormattedTextField(maskCEP);
        field_end_cidade = new javax.swing.JTextField();
        panel_telefone = new javax.swing.JPanel();
        label_tel_celular = new javax.swing.JLabel();
        label_tel_comercial = new javax.swing.JLabel();
        try {     maskCOM = new MaskFormatter("(##) ####-####"); } catch (Exception ex){     System.out.println("Erro ao setar máscara no field_tel_comercial do fornecedor."); }
        field_tel_comercial = new JFormattedTextField(maskCOM);
        try {     maskCEL = new MaskFormatter("(##) ####-####"); } catch (Exception ex){     System.out.println("Erro ao setar máscara no field_tel_celular do fornecedor."); }
        field_tel_celular = new JFormattedTextField(maskCEL);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Fornecedores");

        label_titulo.setFont(label_titulo.getFont().deriveFont(label_titulo.getFont().getStyle() | java.awt.Font.BOLD, 25));
        label_titulo.setForeground(new java.awt.Color(255, 0, 0));
        label_titulo.setText("Cadastro de Fornecedores");

        panel_fornecedor.setPreferredSize(new java.awt.Dimension(970, 400));

        botao_primeiro.setFont(new java.awt.Font("Tahoma", 1, 11));
        botao_primeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/primeiro_registro.gif"))); // NOI18N
        botao_primeiro.setToolTipText("Ir para o primeiro cliente");
        botao_primeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_primeiroActionPerformed(evt);
            }
        });

        botao_anterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/registro_anterior.gif"))); // NOI18N
        botao_anterior.setToolTipText("Cliente anterior");
        botao_anterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_anteriorActionPerformed(evt);
            }
        });

        field_codigo.setCursor(new java.awt.Cursor(java.awt.Cursor.E_RESIZE_CURSOR));
        field_codigo.setEditable(false);
        field_codigo.setForeground(new java.awt.Color(255, 51, 102));

        botao_proximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/proximo_registro.gif"))); // NOI18N
        botao_proximo.setToolTipText("Próximo cliente");
        botao_proximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_proximoActionPerformed(evt);
            }
        });

        botao_ultimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/ultimo_registro.gif"))); // NOI18N
        botao_ultimo.setToolTipText("Ir para o último cliente");
        botao_ultimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_ultimoActionPerformed(evt);
            }
        });

        panel_pesquisar.setBackground(new java.awt.Color(153, 255, 153));

        field_pesquisa.setToolTipText("Digite aqui as iniciais do cliente.");
        field_pesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                field_pesquisaActionPerformed(evt);
            }
        });

        label_pesquisar.setFont(new java.awt.Font("Tahoma", 1, 14));
        label_pesquisar.setText("PESQUISAR:");

        javax.swing.GroupLayout panel_pesquisarLayout = new javax.swing.GroupLayout(panel_pesquisar);
        panel_pesquisar.setLayout(panel_pesquisarLayout);
        panel_pesquisarLayout.setHorizontalGroup(
            panel_pesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_pesquisarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label_pesquisar)
                .addGap(18, 18, 18)
                .addComponent(field_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(25, Short.MAX_VALUE))
        );
        panel_pesquisarLayout.setVerticalGroup(
            panel_pesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_pesquisarLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_pesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_pesquisar)
                    .addComponent(field_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        botao_gravar.setFont(new java.awt.Font("Tahoma", 1, 14));
        botao_gravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/grava_registro.gif"))); // NOI18N
        botao_gravar.setText("Gravar");
        botao_gravar.setToolTipText("Gravar novo cliente");
        botao_gravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_gravarActionPerformed(evt);
            }
        });

        botao_excluir.setFont(new java.awt.Font("Tahoma", 1, 14));
        botao_excluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/delete_registro.gif"))); // NOI18N
        botao_excluir.setText("Excluir");
        botao_excluir.setToolTipText("Excluir cliente");
        botao_excluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_excluirActionPerformed(evt);
            }
        });

        botao_novo.setFont(new java.awt.Font("Tahoma", 1, 14));
        botao_novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/novo_registro.gif"))); // NOI18N
        botao_novo.setText("Novo");
        botao_novo.setToolTipText("Novo registro");
        botao_novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_novoActionPerformed(evt);
            }
        });

        botao_alterar.setFont(new java.awt.Font("Tahoma", 1, 14));
        botao_alterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/alterar_registro.gif"))); // NOI18N
        botao_alterar.setText("Alterar");
        botao_alterar.setToolTipText("Alterar cliente cadastrado");
        botao_alterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_alterarActionPerformed(evt);
            }
        });

        panel_dados_fornecedor.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Fornecedor", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N

        label_marca.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_marca.setText("Marca:");

        label_email.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_email.setText("E-mail:");

        label_cnpj.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_cnpj.setText("CNPJ:");

        label_nomeFantasia.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_nomeFantasia.setText("Nome Fantasia:");

        label_site.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_site.setText("Site:");

        label_contato.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_contato.setText("Contato:");

        javax.swing.GroupLayout panel_dados_fornecedorLayout = new javax.swing.GroupLayout(panel_dados_fornecedor);
        panel_dados_fornecedor.setLayout(panel_dados_fornecedorLayout);
        panel_dados_fornecedorLayout.setHorizontalGroup(
            panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_dados_fornecedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel_dados_fornecedorLayout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(label_site)
                            .addComponent(label_email)
                            .addComponent(label_contato)
                            .addGroup(panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(label_marca)
                                .addComponent(label_cnpj))))
                    .addComponent(label_nomeFantasia))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(field_marca, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                    .addComponent(field_email, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                    .addComponent(field_contato, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                    .addComponent(field_nomeFantasia, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                    .addComponent(field_site, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                    .addComponent(field_cnpj, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE))
                .addContainerGap())
        );
        panel_dados_fornecedorLayout.setVerticalGroup(
            panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_dados_fornecedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(field_nomeFantasia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label_nomeFantasia))
                .addGap(11, 11, 11)
                .addGroup(panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(field_marca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label_marca))
                .addGap(11, 11, 11)
                .addGroup(panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_cnpj, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(field_cnpj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(field_contato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label_contato))
                .addGap(9, 9, 9)
                .addGroup(panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(field_email, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label_email))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panel_dados_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(field_site, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label_site))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panel_endereco.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Endereço", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N

        label_end_cidade.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_end_cidade.setText("Cidade:");

        label_end_rua.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_end_rua.setText("Rua:");

        label_end_bairro.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_end_bairro.setText("Bairro:");

        label_end_cep.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_end_cep.setText("CEP:");

        javax.swing.GroupLayout panel_enderecoLayout = new javax.swing.GroupLayout(panel_endereco);
        panel_endereco.setLayout(panel_enderecoLayout);
        panel_enderecoLayout.setHorizontalGroup(
            panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_enderecoLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(label_end_rua)
                    .addComponent(label_end_bairro)
                    .addComponent(label_end_cep)
                    .addComponent(label_end_cidade))
                .addGap(18, 18, 18)
                .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(field_end_bairro, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(field_end_cep, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(field_end_rua, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(field_end_cidade, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE))
                .addContainerGap())
        );
        panel_enderecoLayout.setVerticalGroup(
            panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_enderecoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel_enderecoLayout.createSequentialGroup()
                        .addComponent(field_end_rua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(field_end_bairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label_end_bairro))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(label_end_cep)
                            .addComponent(field_end_cep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(label_end_rua, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(panel_enderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_end_cidade)
                    .addComponent(field_end_cidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        panel_telefone.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Telefone", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N

        label_tel_celular.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_tel_celular.setText("Celular:");

        label_tel_comercial.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_tel_comercial.setText("Comercial:");

        javax.swing.GroupLayout panel_telefoneLayout = new javax.swing.GroupLayout(panel_telefone);
        panel_telefone.setLayout(panel_telefoneLayout);
        panel_telefoneLayout.setHorizontalGroup(
            panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_telefoneLayout.createSequentialGroup()
                .addGroup(panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel_telefoneLayout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(label_tel_celular))
                    .addGroup(panel_telefoneLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(label_tel_comercial)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(field_tel_celular, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                    .addComponent(field_tel_comercial, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE))
                .addContainerGap())
        );
        panel_telefoneLayout.setVerticalGroup(
            panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_telefoneLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(field_tel_comercial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label_tel_comercial))
                .addGap(9, 9, 9)
                .addGroup(panel_telefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label_tel_celular)
                    .addComponent(field_tel_celular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout panel_fornecedorLayout = new javax.swing.GroupLayout(panel_fornecedor);
        panel_fornecedor.setLayout(panel_fornecedorLayout);
        panel_fornecedorLayout.setHorizontalGroup(
            panel_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_fornecedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panel_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panel_fornecedorLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(panel_dados_fornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panel_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(panel_fornecedorLayout.createSequentialGroup()
                                .addComponent(botao_primeiro)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botao_anterior)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(field_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botao_proximo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botao_ultimo))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panel_fornecedorLayout.createSequentialGroup()
                                .addComponent(panel_endereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(panel_telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(panel_fornecedorLayout.createSequentialGroup()
                                .addComponent(botao_novo, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botao_gravar)
                                .addGap(3, 3, 3)
                                .addComponent(botao_alterar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botao_excluir)))))
                .addContainerGap(67, Short.MAX_VALUE))
        );
        panel_fornecedorLayout.setVerticalGroup(
            panel_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_fornecedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panel_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panel_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(field_codigo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(botao_proximo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 31, Short.MAX_VALUE)
                        .addComponent(botao_anterior, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 31, Short.MAX_VALUE)
                        .addComponent(botao_primeiro, javax.swing.GroupLayout.PREFERRED_SIZE, 31, Short.MAX_VALUE)
                        .addComponent(botao_ultimo, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(10, 10, 10)
                .addGroup(panel_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panel_dados_fornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panel_fornecedorLayout.createSequentialGroup()
                        .addGroup(panel_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(panel_telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(panel_endereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(40, 40, 40)
                        .addGroup(panel_fornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(botao_excluir, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(botao_alterar, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(botao_gravar, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(botao_novo, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addComponent(label_titulo, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panel_fornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 941, Short.MAX_VALUE)
                .addGap(20, 20, 20))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label_titulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panel_fornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-987)/2, (screenSize.height-430)/2, 987, 430);
    }// </editor-fold>//GEN-END:initComponents
    private void botao_primeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_primeiroActionPerformed
        try {
            this.setAtributos(control.primeiroFornecedor());
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Banco de dados vazio.");
        }
}//GEN-LAST:event_botao_primeiroActionPerformed

    
    private void botao_anteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_anteriorActionPerformed
        try {
            ArrayList<String> result;
            if(field_codigo.getText().equalsIgnoreCase("")){
                result = control.primeiroFornecedor();
                this.setAtributos(result);
            } else {
                result = control.anteriorFornecedor(field_codigo.getText());
                this.setAtributos(result);
            }
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null,"Não exitem mais cadastros.");
        }
}//GEN-LAST:event_botao_anteriorActionPerformed

    private void botao_proximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_proximoActionPerformed
        try {
            ArrayList<String> result;
            if(field_codigo.getText().equalsIgnoreCase("")){
                result = control.primeiroFornecedor();
                this.setAtributos(result);
            } else {
                result = control.proximoFornecedor(field_codigo.getText());
                this.setAtributos(result);
            }
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null,"Não exitem mais cadastros.");
        }
}//GEN-LAST:event_botao_proximoActionPerformed

    private void botao_ultimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_ultimoActionPerformed
        try {
            this.setAtributos(control.ultimoFornecedor());
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Banco de dados vazio.");
        }
}//GEN-LAST:event_botao_ultimoActionPerformed

    private void field_pesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_field_pesquisaActionPerformed
        try {
            this.setAtributos(control.pesquisa_digitacao(field_pesquisa.getText().length(), field_pesquisa.getText()));
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Nenhum cadastro encontrado.");
        }
}//GEN-LAST:event_field_pesquisaActionPerformed

    private void botao_gravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_gravarActionPerformed
        try {
            if(field_codigo.getText().equalsIgnoreCase("") && field_nomeFantasia.getText().equalsIgnoreCase("") )
                JOptionPane.showMessageDialog(null,"Obrigatório o preenchimento do campo: Nome Fantasia");
            else {
                if(!field_codigo.getText().equalsIgnoreCase("") && !field_nomeFantasia.getText().equalsIgnoreCase("") )
                    JOptionPane.showMessageDialog(null,"Cadastro do cliente "+field_nomeFantasia.getText()+" já foi realizado.");
                else {
                    if(field_codigo.getText().equalsIgnoreCase("") && !field_nomeFantasia.getText().equalsIgnoreCase("") ){
                        control.cadastraFornecedor(
                            field_nomeFantasia.getText(),
                            field_marca.getText(),
                            field_cnpj.getText(),
                            field_contato.getText(),
                            field_email.getText(),
                            field_site.getText(),
                            field_tel_celular.getText(),
                            field_tel_comercial.getText(),
                            field_end_rua.getText(),
                            field_end_bairro.getText(),
                            field_end_bairro.getText(),
                            field_end_cidade.getText());
                        JOptionPane.showMessageDialog(null,"Gravação realizada com sucesso!");
                    }
                }
            }
        } catch (SQLException erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Problemas no banco de dados! \nNão foi possível efetuar a gravação do cadastro!");
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Problemas para gravar o cadastro!");
        }
}//GEN-LAST:event_botao_gravarActionPerformed

    private void botao_excluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_excluirActionPerformed
        try {
            if(!field_codigo.getText().equalsIgnoreCase("")){
                control.excluir(field_codigo.getText());
                this.limpaFields();
            }
            else
                JOptionPane.showMessageDialog(null, "Primeiro selecione um cadastro!");
        } catch (Exception erro) {
                System.out.println("Erro: " + erro.getMessage());
                JOptionPane.showMessageDialog(null, "Não foi possível efetuar a exclusão do cadastro!");
        }
}//GEN-LAST:event_botao_excluirActionPerformed

    private void botao_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_novoActionPerformed
        this.limpaFields();
}//GEN-LAST:event_botao_novoActionPerformed

    private void botao_alterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_alterarActionPerformed
        try {
            if(!field_codigo.getText().equalsIgnoreCase("")){
                control.alterarFornecedor(
                        field_codigo.getText(),
                        field_nomeFantasia.getText(),
                        field_contato.getText(),
                        field_cnpj.getText(),
                        field_site.getText(),
                        field_marca.getText(),
                        field_email.getText(),
                        field_tel_celular.getText(),
                        field_tel_comercial.getText(),
                        field_end_rua.getText(),
                        field_end_bairro.getText(),
                        field_end_cep.getText(),
                        field_end_cidade.getText());
                JOptionPane.showMessageDialog(null,"Alteração realizada com sucesso!");
            }
            else
                JOptionPane.showMessageDialog(null, "Primeiro selecione um cadastro!");
        } catch (SQLException erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Problemas no banco de dados! \nNão foi possível efetuar a alteração do cadastro!");
        } catch (Exception erro) {
            System.out.println("Erro: " + erro.getMessage());
            JOptionPane.showMessageDialog(null, "Problemas para alterar o cadastro!");
        }
}//GEN-LAST:event_botao_alterarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botao_alterar;
    private javax.swing.JButton botao_anterior;
    private javax.swing.JButton botao_excluir;
    private javax.swing.JButton botao_gravar;
    private javax.swing.JButton botao_novo;
    private javax.swing.JButton botao_primeiro;
    private javax.swing.JButton botao_proximo;
    private javax.swing.JButton botao_ultimo;
    private javax.swing.JFormattedTextField field_cnpj;
    private java.awt.TextField field_codigo;
    private javax.swing.JTextField field_contato;
    private javax.swing.JTextField field_email;
    private javax.swing.JTextField field_end_bairro;
    private javax.swing.JFormattedTextField field_end_cep;
    private javax.swing.JTextField field_end_cidade;
    private javax.swing.JTextField field_end_rua;
    private javax.swing.JTextField field_marca;
    private javax.swing.JTextField field_nomeFantasia;
    private javax.swing.JTextField field_pesquisa;
    private javax.swing.JTextField field_site;
    private javax.swing.JFormattedTextField field_tel_celular;
    private javax.swing.JFormattedTextField field_tel_comercial;
    private javax.swing.JLabel label_cnpj;
    private javax.swing.JLabel label_contato;
    private javax.swing.JLabel label_email;
    private javax.swing.JLabel label_end_bairro;
    private javax.swing.JLabel label_end_cep;
    private javax.swing.JLabel label_end_cidade;
    private javax.swing.JLabel label_end_rua;
    private javax.swing.JLabel label_marca;
    private javax.swing.JLabel label_nomeFantasia;
    private javax.swing.JLabel label_pesquisar;
    private javax.swing.JLabel label_site;
    private javax.swing.JLabel label_tel_celular;
    private javax.swing.JLabel label_tel_comercial;
    private javax.swing.JLabel label_titulo;
    private javax.swing.JPanel panel_dados_fornecedor;
    private javax.swing.JPanel panel_endereco;
    private javax.swing.JPanel panel_fornecedor;
    private javax.swing.JPanel panel_pesquisar;
    private javax.swing.JPanel panel_telefone;
    // End of variables declaration//GEN-END:variables

}
